﻿Imports Microsoft.VisualBasic
Imports System.Data
Public Class PublicFunction
    Public Shared Function GetChild(ByVal fctr As Decimal) As DataSet
        Dim ds As New DataSet
        Dim dt As DataTable = ds.Tables.Add("Items")
        dt.Columns.Add("FundCenterCode", Type.GetType("System.Decimal"))
        dt.Columns.Add("Description", Type.GetType("System.String"))
        dt.Columns.Add("Level", Type.GetType("System.Decimal"))
        Dim adapter As New BasicDataTableAdapters.FCTR_ChildTableAdapter
        Dim datatable As New BasicData.FCTR_ChildDataTable
        datatable = adapter.GetOwnData(fctr)
        For Each row As BasicData.FCTR_ChildRow In datatable
            Dim r As DataRow
            r = dt.NewRow()
            r("FundCenterCode") = row.FundCenterCode
            r("Description") = row.Description
            r("Level") = row.Level
            dt.Rows.Add(r)

        Next
        GetChildByParent(fctr, ds, dt)
        Return ds
    End Function
    Public Shared Function GetChild2(ByVal user_id As String) As DataSet
        Dim ds As New DataSet
        Dim dt As DataTable = ds.Tables.Add("Items")
        dt.Columns.Add("FundCenterCode", Type.GetType("System.Decimal"))
        dt.Columns.Add("Description", Type.GetType("System.String"))
        Dim adapter As New BasicDataTableAdapters.FCTR_ChildTableAdapter
        Dim datatable As New BasicData.FCTR_ChildDataTable
        datatable = adapter.GetDataByUsers2(user_id)
        For Each row As BasicData.FCTR_ChildRow In datatable
            Dim r As DataRow
            r = dt.NewRow()
            r("FundCenterCode") = row.FundCenterCode
            r("Description") = row.Description
            dt.Rows.Add(r)

        Next

        Return ds
    End Function
    Shared Sub GetChildByParent(ByVal parent_id As String, ByRef ds As DataSet, ByRef dt As DataTable)
        Dim adapter As New BasicDataTableAdapters.FCTR_ChildTableAdapter
        Dim datatable As New BasicData.FCTR_ChildDataTable
        datatable = adapter.GetChild(parent_id)
        For Each row As BasicData.FCTR_ChildRow In datatable
            Dim r As DataRow
            r = dt.NewRow()
            r("FundCenterCode") = row.FundCenterCode
            r("Description") = row.Description
            r("Level") = row.Level
            dt.Rows.Add(r)
            GetChildByParent(row.FundCenterCode, ds, dt)
        Next
    End Sub
End Class
